package com.lishe.lishe.lishe.module.shopingcart.http;

import com.lishe.lishe.asynchttp.HttpUtils;
import com.lishe.lishe.lishe.common.Globals;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

/**
 * Created by lwa on 2017/9/6.
 * 购物车相关接口
 */

public class HttpShopppingCart {
    //数据所在的表
    private static final String TABLE_ORDER = "Order/";
    private static final String TABLE_USER = "User/";

    /**
     * 购物车列表
     *
     * @param token
     */
    public static void getGoodsCartList(String token, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_ORDER + "cart/", params, response);
    }

    /**
     * 移出购物车的商品(购物车删除按钮事件)
     *
     * @param token
     * @param gid      商品ID
     * @param response
     */
    public static void removeGoodsFromGoodsCart(String token, String gid, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("gid", gid);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_ORDER + "delFromCart/"+"gid/"+gid+"/", params, response);
    }

    /**
     * 修改物车的商品数量的加减
     * @param token
     * @param cartId   购物车商品的ID
     * @param num      变更成的数量
     * @param response
     */

    public static void updataGoodsCountFromGoodsCart(String token, String cartId, String num, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("cartId", cartId);
        params.put("num", num);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_ORDER + "opCart/", params, response);
    }

    /**
     * 库存检测
     *
     * @param token
     * @param sku_id   商品的sku_id
     * @param address  点击的地址
     * @param item_id  商品的id
     * @param shop_id  商铺的ID
     * @param response
     */

    public static void checkSku(String token, String sku_id, String address, String item_id, String shop_id, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        params.put("sku_id", sku_id);
        params.put("address", address);
        params.put("item_id", item_id);
        params.put("shop_id", shop_id);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_ORDER + "checkSku/", params, response);
    }

    /**
     * 获取默认收货地址（取def_addr=1为默认地址）
     *
     * @param token
     * @param response
     */
    public static void getReceiveAddress(String token, ResponseHandlerInterface response) {
        RequestParams params = new RequestParams();
        params.put("token", token);
        HttpUtils.post(Globals.LISHE_URL + "Home/" + TABLE_USER + "addrList/", params, response);
    }

}
